package cqie.cn.frame;

import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-09-22 周三
 * @time 10:18
 * @description 启动程序
 */
@Log
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan("cqie.cn.frame.mapper")
public class MainApplication {
    private static final String SWAGGER_PATH = "/doc.html";

    public static void main(String[] args) throws UnknownHostException {
//        System.setProperty("spring.devtools.restart.enabled", "false");
//        SpringApplication.run(MainApplication.class, args);
//        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~系统启动成功~~~~~~~~~~~~~~~~~~~~~~~~~~");
//        System.out.println("启动成功，端口号：" + System.getProperty("server.port"));

        ConfigurableApplicationContext application = SpringApplication.run(MainApplication.class, args);
        log.info("..######..##.....##..######...######..########..######...######.\n" +
                ".##....##.##.....##.##....##.##....##.##.......##....##.##....##\n" +
                ".##.......##.....##.##.......##.......##.......##.......##......\n" +
                "..######..##.....##.##.......##.......######....######...######.\n" +
                ".......##.##.....##.##.......##.......##.............##.......##\n" +
                ".##....##.##.....##.##....##.##....##.##.......##....##.##....##\n" +
                "..######...#######...######...######..########..######...######.");
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        log.info("\n------------------------------------------------------\n\t" +
                "Application  is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + path + SWAGGER_PATH + "\n\t" +
//                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
                "----------------------------------------------------------");
    }
}
